import java.util.Scanner;
//水仙花数：一个随机数，有几位，他的各个位的几位次方之和等于本身
public class Number_of_daffodils {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        for (int i = 0; i < n; i++) {
            int count = 0;//记位数
            int tmp = i;//123
            int sum = 0;
            //先求位数
            while (tmp != 0){
                count++;
                tmp /= 10;
            }
            tmp = i;
            //各位的位数次方和
            while (tmp != 0){
                sum += Math.pow(tmp % 10, count);
                tmp /= 10;
            }
            if(sum == i){
                System.out.println(sum);
            }
        }
    }
}
